﻿Imports Microsoft.VisualBasic
Imports System.Net.Mail

Public Class Emails
    Public Function OdesliMail(ByVal komu As MailAddress, ByVal predmet As String, ByVal zprava As String) As Boolean
        Dim Msg As New MailMessage()
        Dim Senderx As New SmtpClient()

        Msg.From = New MailAddress("admin@horejsi.cz", "Web Hořejší")
        Msg.Subject = predmet
        Msg.Body = zprava


        Msg.To.Add(komu)
        Msg.IsBodyHtml = True
        Msg.Priority = MailPriority.High

        Try
            Senderx.Send(Msg)
        Catch ex As Exception
            Return False
        End Try
        Return True
    End Function

    Public Function OdesliMail(ByVal komu As MailAddress, ByVal predmet As String, ByVal zprava As String, ByVal skrykopie As MailAddress) As Boolean
        Dim Msg As New MailMessage()
        Dim Senderx As New SmtpClient()

        Msg.From = New MailAddress("admin@horejsi.cz", "Web Hořejší")
        Msg.Subject = predmet
        Msg.Body = zprava

        If String.IsNullOrEmpty(skrykopie.Address) Then
            Msg.Bcc.Add(skrykopie)
        End If

        Msg.To.Add(komu)
        Msg.IsBodyHtml = True
        Msg.Priority = MailPriority.High

        Try
            Senderx.Send(Msg)
        Catch ex As Exception
            Return False
        End Try
        Return True
    End Function

    Public Function OdesliMail(ByVal od As MailAddress, ByVal komu As MailAddress, ByVal predmet As String, ByVal zprava As String, Optional ByVal kopie As MailAddress = Nothing) As Boolean
        Dim Msg As New MailMessage()
        Dim Senderx As New SmtpClient()
        Dim Alert As Alerts = New Alerts

        'Msg.From = New System.Net.Mail.MailAddress("objednavky@horejsi.cz", "e-Obchod Hořejší")
        Msg.From = od
        Msg.Subject = predmet
        Msg.Body = zprava


        Msg.To.Add(komu)
        If Not IsNothing(kopie) Then
            Msg.Bcc.Add(kopie)
            'Msg.Bcc.Add("mr.datel@gmail.com")
        End If
        Msg.IsBodyHtml = True


        Try
            Senderx.Send(Msg)
        Catch ex As Exception
            Alert.Show("Pozor! Nepodařilo se odeslat mail o chybě!", "Pozor")
            Return False
        End Try
        Return True
    End Function

    Public Function OdesliMailx(ByVal komu As MailAddress, ByVal predmet As String, ByVal zprava As String) As String
        Dim Msg As New MailMessage()
        Dim Senderx As New SmtpClient()

        Msg.From = New MailAddress("admin@horejsi.cz", "Web Hořejší")
        Msg.Subject = predmet
        Msg.Body = zprava


        Msg.To.Add(komu)
        Msg.IsBodyHtml = True
        Msg.Priority = MailPriority.High

        Try
            Senderx.Send(Msg)
            Return "OK"
        Catch ex As Exception
            Return ex.Message
        End Try
        Return True
    End Function

End Class
